package com.herch.web.controller.system;

import com.herch.common.annotation.Log;
import com.herch.common.core.controller.BaseController;
import com.herch.common.core.domain.AjaxResult;
import com.herch.common.core.page.TableDataInfo;
import com.herch.common.enums.BusinessType;
import com.herch.common.utils.poi.ExcelUtil;
import com.herch.system.domain.HqEquipmentInfo;
import com.herch.system.service.IHqEquipmentInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 设备信息管理Controller
 * 
 * @author ruoyi
 * @date 2023-12-14
 */
@RestController
@RequestMapping("/equipment/info")
public class HqEquipmentInfoController extends BaseController
{
    @Autowired
    private IHqEquipmentInfoService hqEquipmentInfoService;

    /**
     * 查询设备信息管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(HqEquipmentInfo hqEquipmentInfo)
    {
        startPage();
        List<HqEquipmentInfo> list = hqEquipmentInfoService.selectHqEquipmentInfoList(hqEquipmentInfo);
        return getDataTable(list);
    }

    /**
     * 导出设备信息管理列表
     */
    @Log(title = "设备信息管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, HqEquipmentInfo hqEquipmentInfo)
    {
        List<HqEquipmentInfo> list = hqEquipmentInfoService.selectHqEquipmentInfoList(hqEquipmentInfo);
        ExcelUtil<HqEquipmentInfo> util = new ExcelUtil<HqEquipmentInfo>(HqEquipmentInfo.class);
        util.exportExcel(response, list, "设备信息管理数据");
    }

    /**
     * 获取设备信息管理详细信息
     */
    @GetMapping(value = "/{equipmentId}")
    public AjaxResult getInfo(@PathVariable("equipmentId") String equipmentId)
    {
        return success(hqEquipmentInfoService.selectHqEquipmentInfoByEquipmentId(equipmentId));
    }

    /**
     * 新增设备信息管理
     */
    @Log(title = "设备信息管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody HqEquipmentInfo hqEquipmentInfo) {
        return toAjax(hqEquipmentInfoService.insertHqEquipmentInfo(hqEquipmentInfo));
    }

    /**
     * 修改设备信息管理
     */
    @Log(title = "设备信息管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody HqEquipmentInfo hqEquipmentInfo) {

        return toAjax(hqEquipmentInfoService.updateHqEquipmentInfo(hqEquipmentInfo));
    }

    /**
     * 删除设备信息管理
     */
    @Log(title = "设备信息管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{equipmentIds}")
    public AjaxResult remove(@PathVariable String[] equipmentIds)
    {
        return toAjax(hqEquipmentInfoService.deleteHqEquipmentInfoByEquipmentIds(equipmentIds));
    }
    @GetMapping("/equipmentList")
    public AjaxResult equipmentList() {
        List<HqEquipmentInfo> equipmentList = hqEquipmentInfoService.selectEquipmentName();
        return success(equipmentList);
    }
}
